#pragma once

///////////////////////////////////////////////////////////////////////////
//																		 //
//	Author:		Michael Mozdzierz										 //
//	Date:		12/04/2014												 //
//	Purpose:	Define a class that renders screen elements				 //
//																		 //
///////////////////////////////////////////////////////////////////////////

#include "IDrawable.h"
#include "../EdgeMath/Geometry.h"
#include <vector>
#include "../Shaders/Defs/ConstantBuffers.hlsli"
#include "ConstantBuffer.h"

class ShaderContainer;
class Texture2D;

using namespace std;

// A class that renders data to the screen in rectangles
class ScreenQuad : public IDrawable
{
	VRAM_VS_UI gShaderInfo;
	VRAM_PS_UI pShaderInfo;

	VertexBuffer* vertexBuffer = nullptr;

	mutable IGraphicsResource* srvs[8];

	ShaderContainer* shaderContainer = nullptr;

	ConstantBuffer<VRAM_VS_UI>* gShaderUiBuffer = nullptr;
	ConstantBuffer<VRAM_PS_UI>* pShaderUiBuffer = nullptr;

	////////////////////////<Private Functions>/////////////////////////////////////////////

	void Init(void);

public:
	ScreenQuad(void);
	ScreenQuad(Box2D& bounds);
	virtual ~ScreenQuad(void);

	Box2D getBounds(void) const { return gShaderInfo.region; }

	Box2D getTexRegion(void) const { return gShaderInfo.texRect; }

	Vector4 getColor(void) const { return pShaderInfo.color; }

	void setColor(const Vector4& value) { pShaderInfo.color = value; }

	void setTexRegion(const Box2D& value) { gShaderInfo.texRect = value; }

	void setBounds(Box2D& value) { gShaderInfo.region = value; }

	bool getUseTexture(void) const { return pShaderInfo.use_texture == 1; }

	void setUseTexture(bool value) { pShaderInfo.use_texture = (value ? 1 : 0); }

	/////////////////////////<Interface>///////////////////////////////////////////////////


	virtual VertexBuffer* getVertexBuffer(void) const override { return vertexBuffer; }

	virtual IGraphicsResource** getResourceViews(void) const override { return srvs; }

	virtual int getNumResourceViews(void) const override { return 8; }

	virtual ShaderContainer* getShaderContainer(void) const override { return shaderContainer; }

	virtual Matrix getWorldTransform(void) const override { return Matricies::Identity; }

	virtual void setResourceView(IGraphicsResource* value, unsigned int index) override { srvs[index] = value; }

	virtual void setShaderContainer(ShaderContainer* value) override { shaderContainer = value; }

	////////////////////////<Public Functions>/////////////////////////////////////////////

	void Draw(void);
};